/** This class provides an access interface for all plugins. 
 *  @author Copyright (c) 2004-2005 by chrmac@gmx.de */

package com.jtalker.client;

import java.util.ArrayList;
import java.util.Hashtable;

/**
 * This class provides an access interface for all plugins.
 * 
 * @author ChrM
 */
public class JTalkerClientPluginConnector {
	private JTalkerClientFront parent;

	public JTalkerClientPluginConnector(JTalkerClientFront parent) {
		this.parent = parent;
	}

	public boolean sendMessage(String content, String to, String type, String description, String id) {

		return this.parent.theClient.sendMessage(content, to, type, description, id);
	}

	public boolean isClientOnline() {
		return this.parent.isConnected;
	}

	public boolean savePlugInSettings(JTalkerClientPlugInInterface _plugin, Hashtable<String, String> _settings) {
		// TODO: let plugin save own settings
		return false;
	}

	public Hashtable<String, String> readPlugInSettings(JTalkerClientPlugInInterface _plugin) {
		// TODO: get plugin settings
		return null;
	}

	public String getUserName() {
		return this.parent.theClient.userName;
	}

	public String getServerName() {
		return this.parent.theClient.serverName;
	}

	public boolean createServerAccount(String _new_name, String _new_pass) {
		return this.parent.theClient.createNewAccount(_new_name, _new_pass);
	}

	public boolean openURLInBrowser(String _url) {
		return this.parent.openBrowser(_url);
	}

	public ArrayList<String> getOnlineUsers() {
		ArrayList<String> retList = new ArrayList<String>();
		String tmpName;
		for (int i = 0; i < this.parent.theClient.allMembers.size(); i++) {
			tmpName = this.parent.theClient.allMembers.get(i).short_name;
			// Exclude the user himself
			if (!tmpName.equals(this.getUserName())){
				retList.add(tmpName);
			}
		}

		return retList;
	}

	public void registerForCommandResponse(JTalkerClientCommandInterface object) {
		this.parent.theClient.registerForCommandResponse(object);
	}

	public void deRegisterForCommandResponse(JTalkerClientCommandInterface object) {
		this.parent.theClient.deRegisterForCommandResponse(object);
	}
}
